#include "CAcademyBossData.h"
#include "MsgAcademyBoss.pb.h"
#include "../mainctrl.h"

/************************************************************************/
/*                    CAcademyBossRoleList                              */
/************************************************************************/
int CAcademyBossRoleList::FindAcademyRole(int iAcademyType)
{
    if (iAcademyType <= 0 || iAcademyType > _astRoles.Size())
    {
        CT_WARNING(("AcademyType(%d) invalid, Role size(%d)",iAcademyType,
                    _astRoles.Size()));
        return -1;//因为返回下标 所以这里必须返回负数
    }
    
    return iAcademyType - 1;
}

CAcademyBossRole& CAcademyBossRoleList::GetAcademyRole(int iIndex)
{
    return _astRoles[iIndex];
}

/************************************************************************/
/*                    CAcademyBossAtkUnit                               */
/************************************************************************/
void CAcademyBossAtkUnit::GetAtkRankUnit(MsgAcademyBossAtkRank& stAtkRankUnit)
{
    stAtkRankUnit.set_role_name(_sRoleName());
    stAtkRankUnit.set_attack_value(_iAtkValue);
    stAtkRankUnit.set_academy_type(_iAcademy);
}

/************************************************************************/
/*                    CAcademyBossMonster                               */
/************************************************************************/
template<>
bool CRankArray<CAcademyBossAtkUnit, CAcademyBossMonster::AB_MONSTER_ATK_RANK_COUNT>::IsSame(CAcademyBossAtkUnit& stA, CAcademyBossAtkUnit& stB) const
{
    return (stA.GetGID() == stB.GetGID());
}

template<>
int CRankArray<CAcademyBossAtkUnit, CAcademyBossMonster::AB_MONSTER_ATK_RANK_COUNT>::CmpFunc(CAcademyBossAtkUnit& stA, CAcademyBossAtkUnit& stB) const
{
    if (stA.GetAtkValue() > stB.GetAtkValue())
    {
        return 1;
    }
    else if (stA.GetAtkValue() < stB.GetAtkValue())
    {
        return -1;
    }

    return 0;
}

int CAcademyBossMonster::GetRankRoleOrder(unsigned int uiGID)
{
    for(int i = 0; i < GetRankSize(); ++i)
    {
        CAcademyBossAtkUnit& stAtkRank = GetRankUnit(i);
        if (stAtkRank.GetGID() == uiGID)
        {
            return i;
        }
    }

    return -1;//协商返回-1
}

/************************************************************************/
/*                    CAcademyBossMonList                               */
/************************************************************************/
int CAcademyBossMonList::FindAcademyMon(int iAcademyType)
{
    if (iAcademyType <= 0 || iAcademyType > _astMonsters.Size())
    {
        CT_WARNING(("AcademyType(%d) invalid, Monster size(%d)",iAcademyType,
                    _astMonsters.Size()));
        return -1;//因为返回下标 所以这里必须返回负数
    }
    
    return iAcademyType - 1;
}

CAcademyBossMonster& CAcademyBossMonList::GetAcademyMon(int iIndex)
{
    return _astMonsters[iIndex];
}

/************************************************************************/
/*                    CAcademyBossRandom                                */
/************************************************************************/
void CAcademyBossRandom::AcademyRandom()
{
    if (CMainCtrl::m_pstMain->m_iNow > _iLastRandTime)
    {
        Clear();//必须先初始化
        _aiAcademyRand.Random();
    }
}

int CAcademyBossRandom::FindAcademyRand(int iAcademyType)
{
    if (iAcademyType <= 0 || iAcademyType > _aiAcademyRand.Size())
    {
        CT_WARNING(("AcademyType(%d) invalid, Rand size(%d)",iAcademyType,
                    _aiAcademyRand.Size()));
        return -1;//因为返回下标 所以这里必须返回负数
    }
    
    return iAcademyType - 1;
}

int CAcademyBossRandom::GetAcademyRand(int iIndex)
{
    return _aiAcademyRand[iIndex];
}

/************************************************************************/
/*                    CAcademyBossAct                                   */
/************************************************************************/
int CAcademyBossAct::FindAcademyAct(int iAcademyType)
{
    if (iAcademyType <= 0 || iAcademyType > _astActInfo.Size())
    {
        return -1;//因为返回下标 所以这里必须返回负数
    }
    
    return iAcademyType - 1;
}

CAcademyBossUnit& CAcademyBossAct::GetAcademyAct(int iIndex)
{
    return _astActInfo[iIndex];
}

